<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>">
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="<c:url value='/resource/css/main.css'/>"/>
    <script type="text/javascript" src="<c:url value='/resource/js/jquery-1.11.1.min.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/resource/js/jquery.form.min.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/resource/js/num-alignment.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/resource/js/lCalendar.js'/>"></script>
    <link rel="stylesheet" type="text/css" href="<c:url value='/resource/css/lCalendar.css'/>"/>
    <title>抽取专家</title>
</head>
<body>
<div class="btn_box4">
    <a onclick="goback()" class=" back">返回</a>
</div>
<ul class="zczh_sh ">
    <li>
        <i>评审日期</i>
        <input class="gsname" readonly="" name="input_date" id="tdate" placeholder="请选择评审日期"  data-lcalendar="2011-01-1,2199-12-31" />
    </li>
    <%--<li>--%>
    <%--<i>评审日期</i>--%>
    <%--<input class="gsname" style="-webkit-appearance:none;" type="date" id="tdate" placeholder="请选择评审日期"--%>
    <%--onchange="getFreeExperts(this);"/>--%>
    <%--</li>--%>
    <li>
        <i>时间</i>
        <input class="gsname"  readonly="" name="input_date" id="time" placeholder="请选择评审日期"/>
    </li>
</ul>
<div class="cqzj_main">
    <div class="azj">
        <span>A类专家</span>
        <input id="2" class="alignment" data_edit="true" value="2"/>
        <i id="expert_a"></i>
    </div>
    <div class="azj">
        <span>B类专家</span>
        <input id="3" class="alignment" data_edit="true" value="2"/>
        <i id="expert_b"></i>
    </div>

</div>
<div class="btn_box">
    <input type="button" value="随机抽取专家" class="search_btn all_btn sjzj" onclick="sjcqzj(this);"/>
</div>
<div class="box" style="display: none;">
    <div class="zczh_ch_tab2">
        <div class="cqzj_tab">
            <form action="expert/savezj?flag=pssh&paguid=${ProjectGuid}" id="saveForm" method="post" name="saveForm">
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table2">
                    <thead class="thead">
                    <tr>
                        <td width="25%">姓名</td>
                        <td width="45%">手机</td>
                        <td width="30%" class="nobg">是否重抽</td>
                    </tr>
                    </thead>
                    <tbody id="cqzj">
                    </tbody>
                </table>
            </form>
        </div>
    </div>
    <div class="btn_box3">
        <input class="all_btn sure" type="button" value="保存" onclick="savezj(this);"/>
        <input class="all_btn cancel" type="button" value="取消" onclick="goback()"/>
    </div>

</div>

<script type="text/javascript">
    var calendar = new lCalendar();
    calendar.init({
        'trigger': '#tdate',
        'type': 'date'
    });
    var calendartime = new lCalendar();
    calendartime.init({
        'trigger': '#time',
        'type': 'time'
    });
    function goback() {
        if (!confirm("确定要返回吗？")) {
            return false;
        } else {
            $.ajax({
                url: "<c:url value="expert/getBack"/>",
                type: "post",
                async: false,
                dataType: "json",
                data: {
                    paguid: '${ProjectGuid}'
                },
                success: function (resp) {
                }
            });
//            window.history.go(-1);
            window.location.href="pssh/index.html"
        }
    }
    /*   $(document).ready(function() {
     $(".sjzj").click(function() {
     $(".box").show();
     });
     });*/
    //获取当前日期的空闲专家
    function getFreeExperts(obj) {
        $.ajax({
            url: "expert/getFreeExperts",
            type: "post",
            async: false,
            dataType: "json",
            data: {
                tdate: $(obj).val()
            },
            success: function (resp) {
                if (resp.succ) {
                    $("#expert_a").html(resp.data.experts_a);
                    $("#expert_b").html(resp.data.experts_b);
                } else {
                    alert(resp.msg);
                    return false;
                }
            }
        });
    }
    //随机抽取专家方法
    function sjcqzj(obj) {
        if ($("#tdate").val() == "") {
            alert("请选择评审日期");
            return false;
        }
        if ($("#time").val() == '') {
            alert("请选择评审时间")
            return false;
        }
        if ($("#2").val() != "") {
            if (Number($("#2").val()) > Number($("#expert_a").html())) {
                alert("A类个数专家已超过可选数量");
                return false;
            }
        } else {
            alert("请选择A类专家个数");
            return false;
        }
        if ($("#3").val() != "") {
            if (Number($("#3").val()) > Number($("#expert_b").html())) {
                alert("B类专家已超过可选数量");
                return false;
            }
        } else {
            alert("请选择B类专家个数");
            return false;
        }
        if (!confirm("确定要抽取吗？")) {
            return false;
        } else {
            $.ajax({
                url: "expert/sjcqzj",
                type: "post",
                async: false,
                dataType: "json",
                data: {
                    tdate: $("#tdate").val(),
                    num_a: $("#2").val(),
                    num_b: $("#3").val(),
                    paguid: '${ProjectGuid}'
                },
                beforeSend: function () {
                    $(obj).attr("disabled", true);
                },
                success: function (resp) {
                    $("#tdate").attr({"disabled": true});
//                console.log(resp)
                    var data = resp.data;
//                console.log(data[0])
//                console.log(data)
                    var html = "";
                    for (var i = 0; i < data.length; i++) {
                        html += "<tr>" +
                                "<td>" + "<input value='" + data[i].guid + "' name='expertList[" + i + "].guid' type='hidden'><input value='" + data[i].realname + "' name='expertList[" + i + "].realname' type='hidden'>" + data[i].realname + "</td>" +
                                "<td><input value='" + data[i].phone + "' name='expertList[" + i + "].phone' type='hidden'>" + data[i].phone + "</td>" +
                                "<td id='" + data[i].guid + "'><input class='join' type='hidden' value='${ProjectGuid}' name='expertList[" + i + "].remark' /><a  class='shenbao' onclick=heavy('" + data[i].guid + "','" + i + "','" + data[i].expertstype + "')>重抽</a></td>"
                                + "</tr>";
                    }
                    $("#cqzj").append(html);
                    if (resp.succ) {
                        $(".box").show();
                    } else {
                        alert(resp.msg);
                        return false;
                    }
                }
            });
        }
    }
    //保存专家方法
    function savezj(obj) {
        var mytable = document.getElementById("cqzj")
        for (var i = 0; i < mytable.rows.length; i++) {
//            console.log($('.join')[i].value);
            if ($('.join')[i].value == null || $('.join')[i].value == "") {
                alert("请填写无法参加的理由")
                return false;
            }
        }

        document.saveForm.action = $("#saveForm").attr("action") + "&tdate=" + $("#tdate").val() + "&time=" + $("#time").val();
        $("#saveForm").ajaxSubmit({
            type: "post",
            dataType: "json",
            success: function (resp) {
                if (resp.succ) {
                    alert(resp.msg)
                    window.location.href="pssh/index.html"
                } else {
                    alert(resp.msg);
                    return false;
                }
            }
        });
    }
    //重新抽取
    function heavy(id, i, expertstype) {
        if (!confirm("确定要重新抽取吗？")) {
            return false;
        } else {
            var mytable = document.getElementById("cqzj")
            $("#" + id).html("<input type='hidden' value='1' name='expertList[" + i + "].isleave' /><input name='expertList[" + i + "].remark' class='join' style='width: 86px;' required='required' type='text' placeholder='无法参加理由' />");
            $.ajax({
                url: "<c:url value="expert/cxcqzj"/>",
                type: "post",
                async: false,
                dataType: "json",
                data: {
                    type: expertstype,
                    tdate: $("#tdate").val(),
                    paguid: '${ProjectGuid}'
                },
                success: function (resp) {
                    if (resp.succ) {
                        var data = resp.data;
//                        console.log(resp)
//                        console.log(data[0])
//                        console.log(data)
                        var html = "";
                        html += "<tr>" +
                                "<td>" + "<input value='" + data[0].guid + "' name='expertList[" + mytable.rows.length + "].guid' type='hidden'><input value='" + data[0].realname + "' name='expertList[" + mytable.rows.length + "].realname' type='hidden'>" + data[0].realname + "</td>" +
                                "<td><input value='" + data[0].phone + "' name='expertList[" + mytable.rows.length + "].phone' type='hidden'>" + data[0].phone + "</td>" +
                                "<td id='" + data[0].guid + "'><input class='join' type='hidden' value='${ProjectGuid}' name='expertList[" + mytable.rows.length + "].remark' /><a  class='shenbao' onclick=heavy('" + data[0].guid + "','" + mytable.rows.length + "','" + data[0].expertstype + "')>重抽</a></td>"
                                + "</tr>";
                        $("#cqzj").append(html);
                    } else {
                        alert(resp.msg);
                        return false;
                    }
                }
            });
        }
    }
</script>
</body>
</html>